home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / setNotesAttribute.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.0 KB  |  120 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //
  20. //  Creation Date:    2001
  21. //  Author:        lf
  22. //
  23. //  Procedure Name:
  24. //    setNotesAttribute
  25. //
  26. //  Input Value:
  27. //    Node name, attribute names and type, and new attribute value
  28. //
  29. //  Output Value:
  30. //    None
  31. //
  32.  
  33. global proc setNotesAttribute( 
  34.     string $nodeName, 
  35.     string $longAttrName, string $shortAttrName, string $attrType,
  36.     string $newAttrValue ) 
  37. {
  38.     if( !`objExists $nodeName` ) {
  39.         return;
  40.     }
  41.     // Description: Sets the given "Notes" attribute on the node 
  42.     // to be the new value.  If the attribute doesn't exist,
  43.     // then create it as a dynamic attribute, and set it.
  44.  
  45.     // Warning! $newAttrValue is not really used here even though
  46.     // it's passed in.  It's checked a few times, but ultimately
  47.     // `scrollField -q -text AENotesScrollFIeld` is used.
  48.     // If you replace the scrollField query to use $newAttrValue
  49.     // (which is the proper way to do things), then multi-line
  50.     // entry into the notes area behaves strangely and
  51.     // doesn't preserve carriage returns.
  52.  
  53.     // If the Notes attribute exists, then just update it
  54.     // If the newAttrValue attribute is empty, that means
  55.     // that this attribute is to be deleted.
  56.     //
  57.     if( `attributeQuery -exists -n $nodeName $longAttrName` ) {
  58.         if( !`getAttr -lock ($nodeName + "." + $longAttrName)`) {
  59.         
  60.  
  61.         if( size($newAttrValue) > 0 ) {
  62.             // Update the Notes only if it's changed
  63.             string $currentNotes = `getAttr ($nodeName + "." + $longAttrName)`;
  64.             if( $currentNotes != $newAttrValue ) {
  65.                 $editCmd = ("setAttr " + "-type \"" + $attrType + "\" " 
  66.                         + $nodeName + "." + $longAttrName + 
  67.                         " `scrollField -q -text AENotesScrollField`");
  68.                 if( catch( eval($editCmd)) ) {
  69.                     error(" Could not set attribute: " + $nodeName + "." + $longAttrName);
  70.                 }
  71.             }
  72.         } else {
  73.             // Delete this attribute from the node
  74.             // but only if the attribute is a dynamic one
  75.             //
  76.             string $dynamicAttrs[] = `deleteAttr -q $nodeName`;
  77.             int $i;
  78.             int $numAttrs = size($dynamicAttrs);
  79.             for( $i = 0; $i < $numAttrs; $i ++ ) {
  80.                 if( $dynamicAttrs[$i] == $longAttrName ) {
  81.                     if( catch( deleteAttr ($nodeName + "." + $longAttrName)))
  82.                     {
  83.                         // Problem deleting attribute,
  84.                         // possibly because a script job still refers 
  85.                         // to this attribute
  86.                         warning("Could not delete the notes attribute. Make sure the Extra Attributes section in the Attribute Editor is closed.");
  87.                     }
  88.                     break;
  89.                 }
  90.             }
  91.         }
  92.         }
  93.  
  94.     } else {
  95.  
  96.         // If the Notes attribute doesn't exist, then create it and set it
  97.         //
  98.         if( size($newAttrValue) > 0 ) {
  99.             if( catch(`addAttr -dt $attrType -ln $longAttrName 
  100.                 -sn $shortAttrName $nodeName`) )
  101.             {
  102.                 error(" Could not create dynamic attribute: " 
  103.                     + $nodeName + "." + $longAttrName + " (long name), " 
  104.                     + $nodeName + "." + $shortAttrName + " (short name) ");
  105.             } else {
  106.     
  107.                 // Do same as above and update the Notes attr
  108.                 //
  109.                 $editCmd = ("setAttr " + "-type \"" + $attrType + "\" " 
  110.                             + $nodeName + "." + $longAttrName + 
  111.                         " `scrollField -q -text AENotesScrollField`");
  112.                 if( catch( eval($editCmd)) ) {
  113.                     error(" Could not set attribute: " + $nodeName + "." + $longAttrName);
  114.                 }
  115.             }
  116.         }
  117.     }
  118. }
  119.  
  120.